#ifndef EXAMPLE_UTILS_H
#define EXAMPLE_UTILS_H

#include <thread>

#include <spdlog/spdlog.h>

#define LOG(level, format, ...) spdlog::log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, format, ##__VA_ARGS__)
#define LOGD(format, ...) LOG(spdlog::level::debug, format, ##__VA_ARGS__)
#define LOGI(format, ...) LOG(spdlog::level::info, format, ##__VA_ARGS__)
#define LOGW(format, ...) LOG(spdlog::level::warn, format, ##__VA_ARGS__)
#define LOGE(format, ...) LOG(spdlog::level::err, format, ##__VA_ARGS__)
#define LOGCT(format, ...) LOG(spdlog::level::critical, format, ##__VA_ARGS__)

#define LOGD_IF(cond, format, ...) do{ if(cond) LOGD(format, ##__VA_ARGS__); }while(0)
#define LOGI_IF(cond, format, ...) do{ if(cond) LOGI(format, ##__VA_ARGS__); }while(0)
#define LOGW_IF(cond, format, ...) do{ if(cond) LOGW(format, ##__VA_ARGS__); }while(0)
#define LOGE_IF(cond, format, ...) do{ if(cond) LOGE(format, ##__VA_ARGS__); }while(0)

namespace ccq {
namespace utils {
static void sleep(int seconds) { std::this_thread::sleep_for(std::chrono::seconds(seconds)); }
static void msleep(int milliseconds) { std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); }
static void usleep(int microseconds) { std::this_thread::sleep_for(std::chrono::microseconds(microseconds)); }
}
}

#endif
